home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / EXAMPLES / BROWSE / BROWSE.C < prev    next >
C/C++ Source or Header  |  1992-12-07  |  6KB  |  194 lines

  1. /**************************************************************************
  2.  * BROWSE - The main module for the BROWSE GemFast demo program.
  3.  *
  4.  *  I'm not proud of this code.  It works.  Barely.  It was to be the
  5.  *  beginning of a text editor subsystem you could embed into any existing
  6.  *  application. It was also to be the vehicle I used to develop my
  7.  *  "next generation" idiom for GEM programming, a system which allows
  8.  *  development of black-box subsystems which can be included into an
  9.  *  application without need for any customizing.  GEM event handling
  10.  *  makes this a pretty tall order.  Maybe impossible.  The "next idiom"
  11.  *  project died, both of its own weight, and due to a lack of response
  12.  *  to a paper I published outlining the issues and requesting suggestions
  13.  *  from developers on how to proceed in a way that would work for
  14.  *  everyone.  Be that as it may, this code is still an okay example of
  15.  *  how to handle events with overlapping windows, how to render text
  16.  *  in a window, and how to put a bit of object-orientedness into your
  17.  *  design using plain-old-C code.  It's not a great example of any of
  18.  *  these things, but it's better than nothing, which is what has been
  19.  *  available to date in terms of scrolling window demos.
  20.  *
  21.  *  It's also not commented as much as I think a piece of demo code
  22.  *  should be.  But, I don't have time to do it right, and sparsely-
  23.  *  commented code is surely better than no code at all.  Isn't it?
  24.  *
  25.  *  Ian Lepore
  26.  *  12/07/92
  27.  *************************************************************************/
  28.  
  29. #include <gemfast.h>
  30. #include <osbind.h>
  31. #include "browse.h"
  32. #include "browser.h"
  33.  
  34. #ifndef TRUE
  35.   #define TRUE  1
  36.   #define FALSE 0
  37. #endif
  38.  
  39. #ifndef NULL
  40.   #define NULL 0L
  41. #endif
  42.  
  43. /**************************************************************************
  44.  * Variables for dialogs & resource files.
  45.  *************************************************************************/
  46.  
  47. #define   RSRCFILE  "browse.rsc"
  48.  
  49. static char no_rsrc_alert[] = "[3][ | | Can't open RSC file! | | ][ Fatal ]";
  50.  
  51. OBJECT *menutree;
  52.  
  53. /**************************************************************************
  54.  * prg_exit - shut down GEM and exit.
  55.  *************************************************************************/
  56.  
  57. static void prg_exit()
  58. {
  59.     menu_bar(menutree, FALSE);
  60.     rsrc_free();
  61.     appl_exit();
  62.     _exit(0);
  63. }
  64.  
  65. /**************************************************************************
  66.  * prg_init - fire up AES/VDI, open window, load rsrc, etc.
  67.  *************************************************************************/
  68.  
  69. static void prg_init()
  70. {
  71.     int dmy;
  72.  
  73.     appl_init();
  74.  
  75.     if (!rsrc_load(RSRCFILE)) {
  76.         form_alert(1, no_rsrc_alert);
  77.         prg_exit();
  78.     }
  79.  
  80.     rsrc_gaddr(R_TREE, MENUTREE, &menutree);
  81.  
  82.     menu_bar(menutree, TRUE);
  83.     graf_mouse(ARROW, NULL);
  84. }
  85.  
  86. /**************************************************************************
  87.  * open a browser to display a file, complain and die if it doesn't open.
  88.  *
  89.  *  br_errno will hold a standard TOS error code, and frm_error() uses
  90.  *  strerror() to translate that code to a message.  this works great
  91.  *  under HSC, which has the right error messages for TOS error codes.
  92.  *  with other compilers, your mileage may vary.
  93.  *************************************************************************/
  94.  
  95. static void open_browser()
  96. {
  97.     char    thefile[128];
  98.     Browser *thebrowser;
  99.  
  100.     if (!fsl_dialog(FSL_NORMAL, thefile, NULL, NULL, "Browse File:"))
  101.         return;
  102.  
  103.     if (NULL == (thebrowser = br_file(thefile))) {
  104.         frm_qerror(br_errno, "Can't load %s\n\n", thefile);
  105.     }
  106. }
  107.  
  108. /**************************************************************************
  109.  * process menu items.
  110.  *************************************************************************/
  111.  
  112. static void do_menu(item)
  113.     short   item;
  114. {
  115.     short    top_window;
  116.     short    dmy;
  117.     Browser  *thebrowser;
  118.  
  119.     switch (item) {
  120.  
  121.       case DESKINFO:
  122.  
  123.         frm_qtext("\x7F" "BROWSE\n"
  124.                   "\x7F" "A GemFast example program\n"
  125.                   "\x7F" "which demonstrates handling\n"
  126.                   "\x7F" "scrolling text in a window.\n"
  127.                          " \n"
  128.                   "\x7F" "Source and program are\n"
  129.                   "\x7F" "Public Domain\n"
  130.                   "\x7F" "by Ian Lepore\n");
  131.         break;
  132.  
  133.       case MENFOPEN:
  134.  
  135.         open_browser();
  136.         break;
  137.  
  138.       case MENFCLOS:
  139.  
  140.         top_window = wnd_top();
  141.         if (NULL == (thebrowser = br_handle(top_window))) {
  142.             frm_qtext("The top window is not\na browser window!");
  143.         } else {
  144.             br_delete(thebrowser);
  145.         }
  146.         break;
  147.  
  148.       case MENFQUIT:
  149.  
  150.         br_shutdown();
  151.         prg_exit();
  152.         break;
  153.  
  154.     }
  155. }
  156.  
  157. /**************************************************************************
  158.  * main - Initialize, invoke event_multi handler, exit if it returns.
  159.  *************************************************************************/
  160.  
  161. void main()
  162. {
  163.     XMULTI  xm;
  164.     short   event;
  165.     short   *msgbuff;
  166.  
  167.     prg_init();
  168.  
  169.     xm.mflags = MU_MESAG;
  170.  
  171.     do_menu(MENFOPEN);
  172.  
  173.     for (;;) {
  174.  
  175.         evnx_multi(&xm);    // get event
  176.         br_event(&xm);      // dispatch it to browser subsystem
  177.  
  178.         event = xm.mwhich;
  179.         msgbuff = (short *)xm.msgbuf;
  180.  
  181.         if (event & MU_MESAG) {
  182.             switch (msgbuff[0]) {
  183.  
  184.             case MN_SELECTED:
  185.  
  186.                 do_menu(msgbuff[4]);
  187.                 menu_tnormal(menutree, msgbuff[3], TRUE);
  188.                 break;
  189.  
  190.             } /* END switch (msgbuff[0]) */
  191.         } /* END if (message event) */
  192.     } /* END for(;;) */
  193. }
  194.